package com.asman.worker.rn

import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import android.util.Log
import com.asman.worker.gallery.GalleryListActivity
import com.facebook.react.bridge.BaseActivityEventListener
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.multipleimageselect.helpers.Constants
import java.util.*

/**
 * author : ybk
 * date   : 2019-07-18 19:47
 * desc   :
 */
class NativePageJump(reactContext: ReactApplicationContext) :
    ReactContextBaseJavaModule(reactContext) {

    override fun getName(): String {
        return "NativePageJump"
    }

    override fun getConstants(): Map<String, Any>? {
        return HashMap()
    }

    private val mActivityEventListener = object : BaseActivityEventListener() {
        override fun onActivityResult(
            activity: Activity?, requestCode: Int, resultCode: Int, intent: Intent?
        ) {
        }
    }

    init {
        reactContext.addActivityEventListener(mActivityEventListener)
    }

    /**
     * 跳转应用通知管理
     */
    @ReactMethod
    fun notifSetting() {
        val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
        val uri = Uri.fromParts("package", currentActivity?.packageName, null)
        intent.data = uri
        currentActivity?.startActivityForResult(intent, 10000)
    }

    /**
     * 跳转工地直播拍照的相册列表
     */
    @ReactMethod
    fun gallery(folderName: String) {
        val intent = Intent(currentActivity, GalleryListActivity::class.java)
        intent.putExtra(Constants.INTENT_EXTRA_ALBUM, folderName)
//        intent.putExtra(Constants.INTENT_EXTRA_ALBUM, "牛牛搭新家工地")
        currentActivity?.startActivity(intent)
    }

}
